package com.gary.heapJUC;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author peng_rui
 * @date 2022/3/16
 */
public class CyclicBarrierDemo {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> {
            System.out.println("88888888888888发财啦");
        });

        for (int i = 0; i < 7; i++) {
            new Thread(() -> {
                try {
                    System.out.println("我是" + Thread.currentThread().getName());
                    cyclicBarrier.await();
                    System.out.println(Thread.currentThread().getName() + "我们发财啦！！！");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }, "同学"+i).start();
        }
    }
}
